<?php
/**
 * Contact Sources List Grid
 * This is the administration interface to add/update/delete 
 * contact sources.
 *
 * @author Xavier VILAIN
 * @package Hive\Ressource
 * @license #license-hive#
 *  
 */
use Fox\Behaviors;
use Fox\Html\Button;
use Fox\Grid;
use Hive\Contact\Source;
use Fox\Generator;
use Fox\Dao\SqlFragment;
$xview = Xview::instance();
// Customizing
$customizing = Hive\Admin\Customizing::instance();
$customizing->trackSummaryPage(array('mod' =>'contacts','act'=>'sources','sac' => null));

if(!Fox\Authorization\Manager::check(Hive\Authorizations::CONTACT_SOURCES_W)) {
	echo $xview->accessDenied(Msg(Hive::BUNDLE,Hive::ERR_ADMIN_ACCES_DENIED),null,true);
	exit;
}

$reload = $xview->val('reload',false);
$screen = new Fox\Html\Screen('sList');
$screen->pageTitle(Msg(Hive::BUNDLE,Hive::CONTACT_SOURCE_CUSTOMIZING));

$bAction = new Fox\Html\Button('add','?');
$bAction->color(Fox\Html\Button::COLOR_WARNING)
		->behaviors(Fox\Behaviors::action(
			Fox\Generator::url('contacts','sources','modify'),
			true
		));
	
$screen->message('<p class="prettyprint">'.$bAction->display().Msg(Hive::BUNDLE,Hive::YOU_WILL_FIND_BELLOW_THE_LIST_OF_AVAILABLE_CONTACT_SOURCES).'</p>');

$sources = Fox\Dao::finder(Source::className())
		->find();
		
$grid = new Grid('incommings');
$grid->fieldcat(array('label','standard','active','iedit'));
$grid->bootstrapGrid();
$grid->fieldcat()->field('standard')->width(1);
$grid->fieldcat()->switchToObjectMode();
$grid->fieldcat()->setGenerators(array(
	'label' => Generator::call('label'),
	'iedit' => Generator::useValue('#')
));
$grid->fieldcat()->field('iedit')->renderer()
		->behaviors(Behaviors::action(
			Generator::url('contacts','sources','modify',array('inlineid' => Generator::call('getInLineId'))),
			true
		));

$grid->initialize($sources);
$screen->add($grid);
$html = '<div class="source {\'uri\':\'?mod=contacts&act=sources\'}" >';
$html .= $screen->display();
$html .= '</div>';
return $html;